//
//  CZDetailLoadingCell.swift
//  GZWeibo007
//
//  Created by OY on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

    class CZDetailLoadingCell: CZDetailCommentCell {
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
            super.init(style: style, reuseIdentifier: reuseIdentifier)
            
            prepareUI()
        }
        
        override func prepareForReuse() {
            super.prepareForReuse()
            
            loadingView.startAnimating()
        }
        
        // MARK: - 准备UI
        override func prepareUI() {
            // 添加子控件
            contentView.addSubview(loadingView)
            contentView.addSubview(messageLabel)
            
            // 添加约束
            loadingView.translatesAutoresizingMaskIntoConstraints = false
            messageLabel.translatesAutoresizingMaskIntoConstraints = false
            
            contentView.addConstraint(NSLayoutConstraint(item: loadingView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: -40))
            
            contentView.addConstraint(NSLayoutConstraint(item: loadingView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
            
            contentView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: loadingView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 5))
            
            contentView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
            
            contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 44))
        }
        
        // MARK: - 懒加载
        /// 菊花
        private lazy var loadingView: UIActivityIndicatorView = {
            let view = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
            
            view.color = UIColor.magentaColor()
            view.startAnimating()
            view.hidesWhenStopped = false
            
            return view
        }()
        
        /// 文字
        private lazy var messageLabel: UILabel = {
            let label = UILabel()
            
            label.text = "正在加载数据..."
            label.textColor = UIColor.lightGrayColor()
            label.sizeToFit()
            
            return label
        }()
    }


